package logic

import (
	"context"
	"mall/mallrpc/internal/svc"
	"mall/mallrpc/mallrpc"
	"mall/model/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddLogic {
	return &UserAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserAddLogic) UserAdd(in *mallrpc.UserAddRequest) (*mallrpc.UserAddResponse, error) {
	// todo: add your logic here and delete this line

	product := mysql.Product{
		UserId: int(in.Userid),
		Name:   in.Name,
		Title:  in.Title,
		Area:   in.Area,
		Price:  float64(in.Price),
		Img:    in.Img,
		Num:    int(in.Num),
	}
	mysql.DB.Debug().Create(&product)

	return &mallrpc.UserAddResponse{Id: int64(product.ID)}, nil
}
